import { message } from 'ant-design-vue'
import { http } from '@/utils/request'

export default function async({ type = '门诊', name = '导出', code = '', searchParams = {} }) {
  const getUrl = () => {
    switch (type) {
      case '门诊':
        return '/outp/export'
      case '住院':
        return '/inp/export'
    }
  }

  http
    .post(getUrl(), { parameters: searchParams, tblcode: code }, { responseType: 'blob' })
    .then((res) => {
      const href = URL.createObjectURL(res.data)
      const element = document.createElement('a')
      element.download = name + '.xlsx'
      element.href = href
      element.click()
    })
    .catch(() => {
      message.error('导出失败，请稍后重试！')
    })
}
